package dagiac;
import java.util.Arrays;
import java.util.Scanner;

import diem.Diem;

public class Dagiac {

	

	/**
	 * @param args
	 */
	private Diem [] arrDiem;
	
	
	public Diem[] getArrDiem() {
		return arrDiem;
	}

	public void setArrDiem(Diem[] arrDiem) {
		this.arrDiem = arrDiem;
	}

	/**
	 * @param arrDiem
	 */
	public Dagiac(Diem[] arrDiem) {
		super();
		this.arrDiem = arrDiem;
	}
	
	/**
	 * 
	 */
	public Dagiac(int n) {
		super();
		// TODO Auto-generated constructor stub
		arrDiem = new Diem[n];
		for (int i = 0; i < arrDiem.length; i++) {
			arrDiem[i] = new Diem();
		}
	}
	
	//nhap da giac 
	public void Nhap() {
		/*
		System.out.print("nhap so canh da giac : ");
		
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		
		*/
		for (int i = 0; i < arrDiem.length; i++) {
			System.out.println("Dinh " + (i+1));
			arrDiem[i].Nhap();
		}
		
	}
	
	
	//xuat da giac
	public void Xuat() {
		// TODO Auto-generated method stub
		for (int j = 0; j < arrDiem.length; j++) {
			
		
			System.out.println("Dinh " + (j+1));
			arrDiem[j].Xuat();
			
		}
	}
	//chu vi da giac 
	public double Chuvi() {
		double s =0 ;
		for (int i = 0; i < arrDiem.length; i++) {
			s += arrDiem[i].KhoangCach(arrDiem[(i+1)/arrDiem.length]); 
		}
		return s;
	}
	//overide
	
	//kiem tra da giac deu
	public String	KT_DaGiacDeu() {
		if (arrDiem.length<3) {
			return "khong phai da giac";
		}
		double [] arrCanh = new double[arrDiem.length];
		
		for (int i = 0; i < arrDiem.length; i++) {
			
			arrCanh[i]= arrDiem[i].KhoangCach(arrDiem[(i+1)/arrDiem.length]); 
		}
		Arrays.sort(arrCanh);
		if (arrCanh[0]==arrCanh[arrCanh.length-1]) {
			return "Da giac deu";
		}
		return "Khong phai da giac deu";
	}
	
	//parse da giac 
	public static Dagiac parseDaGiac() {
		System.out.print("nhap da giac dang Ax,Ay;Bx,By;Cx,Cy;...");
		Scanner scan = new Scanner(System.in);
		
		String str = scan.nextLine();
		
		String [] arrStr = str.split(";");
		Dagiac d = new Dagiac(arrStr.length);
		
		for (int i = 0; i < arrStr.length; i++) {
			d.arrDiem[i] = Diem.parseDiem(arrStr[i]);
		}
		return d;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.print("nhap so canh da giac : ");
		
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		Dagiac d = new Dagiac(n);
		d.Nhap();
		d.Xuat();
		System.out.println(d.Chuvi());
		System.out.println(d.KT_DaGiacDeu());
		Dagiac.parseDaGiac().Xuat();
	}

}
